<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2021/5/30
 * Time: 23:20
 */

namespace app\service;


use app\model\ConfigModel;
use think\facade\Log;
class SearchEnginePushService
{
    /**
     * @param $articleId
     * @return bool|mixed
     */
    public function baidu($articleId){
        $configModel = new ConfigModel();
        $baiduToken = $configModel->where('biz','baidu_token')->value('val');
        if(empty($baiduToken)){
            return false;
        }
        $domain = $configModel->where('biz','domain')->value('val');
        $api = 'http://data.zz.baidu.com/urls?site='.$domain.'&token='.$baiduToken;
        $urls = array(
            'http://'.$domain.'/article/detail/id-'.$articleId
        );
        $ch = curl_init();
        $options =  array(
            CURLOPT_URL => $api,
            CURLOPT_POST => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POSTFIELDS => implode("\n", $urls),
            CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
        );
        curl_setopt_array($ch, $options);
        $result = curl_exec($ch);
        Log::record('百度推送结果'.$result);
       return $result;
    }
}